import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;

public class query {
    private static final String BASE_URL = "http://121.36.106.217:9005/";

    // 查询订单
    public String query(String orderId, String TOKEN) throws IOException {
        Client client = new Client();
        try {
            TOKEN = client.isAvailable();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        // 构建请求URL和参数
        String url = BASE_URL + "/wechat/order/query"; // 微信查询订单接口
//        String url = BASE_URL + "/alipay/order/query"; // 支付宝查询订单接口
        // 付款接口根据支付方式（微信/支付宝）选择不同的URL
        // 此代码以微信为例，支付宝类似处理

        HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
        urlBuilder.addQueryParameter("orderID", orderId);
        urlBuilder.addQueryParameter("token", TOKEN);

        // 创建请求
        Request request = new Request.Builder()
                .url(urlBuilder.build())
                .build();

        // 发送请求并获取响应
        try (Response response = new OkHttpClient().newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            return response.body().string();
        }
    }
}
